package com.hzhc.controller.pad;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hzhc.annotation.SysTemLog;
import com.hzhc.common.BaseController;
import com.hzhc.dto.UserDto;
import com.hzhc.enumBean.ResultUtilCodeEnum;
import com.hzhc.service.TrainPlanDetailService;
import com.hzhc.utils.ResultUtil;
import com.hzhc.utils.TokenUtil;
import com.hzhc.vo.TrainPlanDetailVo;
import lombok.RequiredArgsConstructor;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author dongcy
 * @date 2024/6/4 16:37
 * @description IpadCntrZcTallyController  ipad装车理货
 */
@RestController
@RequestMapping("/ipad")
@RequiredArgsConstructor
public class IpadCntrZcTallyController extends BaseController {

    private final TrainPlanDetailService detailService;


    /**
     * 装车理货(出场)  列表list
     * @param request
     * @param vo
     * @return
     */
    @RequestMapping("/getAllTrainPlanDetail")
    @ResponseBody
    public ResultUtil<List<TrainPlanDetailVo>> getAllTrainPlanDetail(HttpServletRequest request, @RequestBody TrainPlanDetailVo vo){
        Page<TrainPlanDetailVo> page = new Page<>(vo.getPageIndex(),vo.getPageSize());
        List<TrainPlanDetailVo> list = detailService.getAllTrainPlanDetail(page,vo);
        return ResultUtil.build(list,page.getTotal(),page.getPages(), ResultUtilCodeEnum.SUCCESS);
    }

    /**
     * ipad 装车理货
     * @param request
     * @param vo
     * @return
     */
    @PostMapping("/cntrZcTallyIpad")
    @SysTemLog(operModul = "装车理货", operType = "理货", operDesc = "装车理货功能", modular = "IPAD")
    public ResultUtil<T> carTallyIpad(HttpServletRequest request, @RequestBody TrainPlanDetailVo vo){
        UserDto user = TokenUtil.getUser(request);
        vo.setUserId(user.getId());
        vo.setUserName(user.getRealname());
        vo.setAccesspath("平板端");
        if (vo.getIsRectified() !=null && vo.getIsRectified()==0){
            return detailService.carTally(vo);
        }else{
            //待整改
            return detailService.carTallyDzg(vo);
        }
    }

    /**
     * ipad 装车理货 修改 车号 铅封号
     * @param request
     * @param vo
     * @return
     */
    @PostMapping("/zcUpdateCarNo")
    @SysTemLog(operModul = "装车理货", operType = "修改车号铅封号", operDesc = "修改车号铅封号功能", modular = "IPAD")
    public ResultUtil<T> zcUpdateCarNo(HttpServletRequest request, @RequestBody TrainPlanDetailVo vo){
        return detailService.zcUpdateCarNo(vo);
    }

    /**
     * 装车-已理货-未完工箱子批量撤回
     * @param request
     * @param vo
     * @return
     */
    @RequestMapping("/retractRet")
    public ResultUtil<T> retractRet(HttpServletRequest request,@RequestBody TrainPlanDetailVo vo) {
        Long userID = TokenUtil.getUserID(request);
        vo.setUserId(userID);
        return detailService.retractRet(vo);
    }



}
